<%@ page language="java" %>
<%
    response.setHeader("Cache-Control", "no-cache");
    response.setHeader("Pragma", "no-cache");
    response.setDateHeader("max-age", 0);
    response.setDateHeader("Expires", 0);

%>

<%@ page import="java.util.ArrayList,
                java.util.HashMap,java.util.Enumeration,
                com.scalar.chiptrack.operations.packingslip.CustomerShippingLotNumberData,
                com.scalar.chiptrack.operations.packingslip.FinalInventoryData,
                com.scalar.chiptrack.utils.ConfigManager,
                com.scalar.chiptrack.utils.StringUtils,
                com.scalar.chiptrack.commons.Constants,
                com.scalar.chiptrack.commons.SessionKeys,
                com.scalar.chiptrack.users.User,
                com.scalar.chiptrack.users.Functionality"%>
<%@ page import="com.scalar.chiptrack.utils.WorkWeek" %>
<%@ page import="org.apache.struts.util.LabelValueBean" %>

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>

<%
    String closeWindowAfterSessionTimeOut = ( String ) request.getAttribute( "closeWindowAfterSessionExp" );
    String isRequestFromTrackingNoPage = (String) request.getParameter("isReqFromTrackingNoPage");
    if ( closeWindowAfterSessionTimeOut == null )
    {
%>
    <%--<chiptrack:checkLogon sourcePage="/packingSlip.do"/>--%>
<% } %>

<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>

<% User user1 = (User)session.getAttribute (SessionKeys.USER_KEY); %>
<%
	String txtIndex						= request.getParameter("index");
	ArrayList finalInventoryDataList	= (ArrayList) session.getAttribute ( "finalInventoryDataList" );

	String quantityToBeShipped			= (String)request.getParameter( "quantityToBeShipped" );

    boolean issuedPackingSlip			= Boolean.valueOf ( request.getParameter( "issedPackingSlip" ) ).booleanValue();
    String errMsg						= " ";
    boolean viewOnly					= Boolean.valueOf ( ( String ) request.getAttribute( "viewOnly" ) ).booleanValue();

    HashMap requestedQuantityMap		= (HashMap)session.getValue( "requestedQuantity" );
    String  requestedQuantity			= "0";

	String closeWindowAfterSave			= (String)request.getAttribute( "closeWindow" );

    String reqFromVendorInterface       = request.getParameter("isReqFromTrackingNoPage");
    boolean parentPartNoExitsInSubs     = Boolean.valueOf ( ( String ) request.getAttribute( "parentPartNoExitsInSubstitutables") ).booleanValue();
    boolean modifyInventory             = false;
    modifyInventory                     = Boolean.valueOf ( request.getParameter( "modifyInventory") ).booleanValue();

	if ( requestedQuantityMap != null )
    {
        String index = request.getParameter("fieldName").substring(16,17);
        requestedQuantity = (String)requestedQuantityMap.get(index);
    }
%>

<html:html locale="true">

<HEAD>
	<TITLE>Scalarsoft - ChipTrac</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type="text/css" rel="stylesheet">
<SCRIPT language="JavaScript" src="<%=chipTracContext%>/jsp/includes/scripts/validations.js"></SCRIPT>
</HEAD>

<SCRIPT language="JavaScript">

<%
if ( ( closeWindowAfterSave != null ) && ( closeWindowAfterSave.equalsIgnoreCase( "true" ) ) ) {
%>
	window.close();
<%}%>

function openAudit (lotNumber,lotId)
{
    var finalInventoryURL = '<%=chipTracContext%>/jsp/operations/lot_qty_pull_audit.jsp?lotId='+lotId+'&lotNumber=' + lotNumber;
    newWindow = window.open (finalInventoryURL,'lotAudit','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=yes,width=700,height=300,resizable=yes');
    newWindow.focus();
}

///////////////////////////////// STARTS HERE////////////////////////////////////////////

<%--
//var  substitutePartNosJS = '<%=substitutePartNos%>'
//var  subPartNoArray      = substitutePartNosJS.split(",");
--%>

var reqTotQtyShipped;
reqTotQtyShipped = parseInt('<%=quantityToBeShipped%>');
function insertQty(indx)
{
	var formN=document.finalInventoryForm;
	var qtyToPullObj = formN.quantityToPull;
    var lotIdObj = formN.lotId;
	var qtyInObj = formN.hdnQuantityIn;
	var qtyToPullV = qtyToPullObj.value;

    var balancesQtyObj          = formN.lotBalanceQty;
    var lotEnteredByObj         = formN.lotEnteredBy;
    var hiddenQuantityToPullObj = formN.quantityToPullHidden;

    var errorOccured1=false;
    var errorOccured2="";
	if( typeof qtyToPullObj != 'undefined'  )
	{
		if (typeof qtyToPullObj.length == 'undefined' )
		{
            if ( lotIdObj.value == -1 )
			{
                if ( parseInt ( qtyToPullObj.value ) > parseInt ( qtyInObj.value ) )
                {
                    errorOccured1=true;
                    formN.quantityToPull.value="";
                }
            }
            else
			{
                if ( lotEnteredByObj.value == '0' )
                {
                    if ( parseInt ( qtyToPullObj.value ) > parseInt ( balancesQtyObj.value ) )
                    {
                        errorOccured2= balancesQtyObj.value ;
                        formN.quantityToPull.value="";
                    }
                }
            }

		}
		else
		{
			for(var i=0 ; i< qtyToPullObj.length ; i++)
			{
                if ( lotIdObj[i].value == -1 )
			    {
                    if ( parseInt( qtyToPullObj[i].value ) > parseInt( qtyInObj[i].value ) )
                    {
                        //alert("Qty In should be greater then Qty Pulled");
                        //document.finalInventoryForm.txtErrMsg.value='Quantity In should be greater than Quantity Pulled';
                        qtyToPullObj[i].value="";
                        errorOccured1=true;
                    }
                }
                else
			    {
                    if ( lotEnteredByObj[i].value == '0' )
                    {
                        if ( parseInt ( qtyToPullObj[i].value ) > parseInt ( balancesQtyObj[i].value ) )
                        {
                            //alert("Qty In should be greater then Qty Pulled");
                            errorOccured2= balancesQtyObj[i].value ;
                            qtyToPullObj[i].value="";
                        }
                    }
                }
			}
		}
	}
    if(errorOccured1)
    {
         document.finalInventoryForm.txtErrMsg1.value='Quantity In should be greater than Quantity Pulled';
    }
    else
    {
         document.finalInventoryForm.txtErrMsg1.value='';
    }
    if(errorOccured2 != "")
    {
         document.finalInventoryForm.txtErrMsg1.value='Quantity Pulled should be less than available Balance Quantity ' + errorOccured2;
    }
    else if ( errorOccured1 == false )
    {
         document.finalInventoryForm.txtErrMsg1.value='';
    }
	calTotQtyToBeShipped(indx)
}

function calTotQtyToBeShipped(indx)
{

	if( typeof document.finalInventoryForm.quantityToPull != 'undefined'  )
	{
        var errorOccured=false;
		if (typeof document.finalInventoryForm.quantityToPull.length == 'undefined' )
		{
			var QtyToPullSum=0;
			var tempQtyPulled = document.finalInventoryForm.quantityToPull.value;

				if(tempQtyPulled == "")
				{
					tempQtyPulled = "0";
				}
				QtyToPullSum = QtyToPullSum + parseInt(tempQtyPulled);
				if( reqTotQtyShipped >= QtyToPullSum )
				{
					document.finalInventoryForm.qtyTobeShipped.value= reqTotQtyShipped - QtyToPullSum;
				}
				else
				{
					//alert("@Total Qty Shipped should be greater then Total Qty Pulled@");
					QtyToPullSum = document.finalInventoryForm.quantityToPullHidden.value;
					document.finalInventoryForm.qtyTobeShipped.value = reqTotQtyShipped - QtyToPullSum;
					document.finalInventoryForm.quantityToPull.value = document.finalInventoryForm.quantityToPullHidden.value
                    errorOccured = true;
				}
				document.finalInventoryForm.totals.value=QtyToPullSum;
                if(errorOccured)
                {
                    document.finalInventoryForm.txtErrMsg.value='Total Quantity Shipped should be greater then Total Quantity Pulled';
                }
                else
                {
                    document.finalInventoryForm.txtErrMsg.value='';
                }
		}
		else
		{
			//var errorOccured=false;
			var QtyToPullSum=0;

			for(var i=0 ; i< document.finalInventoryForm.quantityToPull.length ; i++)
			{
				var tempQtyPulled = document.finalInventoryForm.quantityToPull[i].value;
				if(tempQtyPulled == "")
				{
					tempQtyPulled = "0";
				}
					QtyToPullSum = QtyToPullSum + parseInt(tempQtyPulled);
					if( reqTotQtyShipped >= QtyToPullSum )
					{
						document.finalInventoryForm.qtyTobeShipped.value = reqTotQtyShipped - QtyToPullSum;
					}
					else
					{
						//alert("@Total Qty Shipped should be greater then Total Qty Pulled@");

						QtyToPullSum = QtyToPullSum - parseInt(document.finalInventoryForm.quantityToPull[indx].value);
						errorOccured = true;
					}
			}
			if(errorOccured)
			{
				document.finalInventoryForm.qtyTobeShipped.value = reqTotQtyShipped - QtyToPullSum;
				//document.finalInventoryForm.quantityToPull[indx].value = 0;
                document.finalInventoryForm.quantityToPull[indx].value =  document.finalInventoryForm.quantityToPullHidden[indx].value
				document.finalInventoryForm.totals.value=QtyToPullSum;
                //document.finalInventoryForm.txtErrMsg.value='Total Quantity Shipped should be greater then Total Quantity Pulled';
                document.finalInventoryForm.txtErrMsg.value='Total Quantity Pulled should be less than or equal to Total Quantity to be Shipped';
			}
			else
			{
				document.finalInventoryForm.totals.value=QtyToPullSum;
                document.finalInventoryForm.txtErrMsg.value='';
			}
		}
	}
}

///////////////////////////////// ENDS HERE////////////////////////////////////////////


function calcDynValues()
{
	//alert("calcDynValues");
    calcBalance();
	//alert("calcQtyToBeShipped");
    calcQtyToBeShipped();
}


var firstTimeCalcBalance = true;
var qtyPulled			 = new Array();

function calcBalance()
{
	// This condition is added by ravikanth on 08-05-2004
	// Because in drop shipment there can be a condition where there are no lots for the PartNumber
	if( typeof document.finalInventoryForm.quantityToPull != 'undefined'  )
	{
		if ( document.finalInventoryForm.quantityToPull.length == null )
		{
			if ( firstTimeCalcBalance )
			{
				if ( document.finalInventoryForm.quantityToPull.value.length != 0 )
				{
					qtyPulled[0] = document.finalInventoryForm.quantityToPull.value;
				}
				else
				{
					qtyPulled[0] = 0;
				}
				if( !isNaN( parseInt( document.finalInventoryForm.initBalances.value ) ) )
				{
					document.finalInventoryForm.balance.value = document.finalInventoryForm.initBalances.value
				}
				firstTimeCalcBalance = false;
			}
			else
			{
				if ( document.finalInventoryForm.quantityToPull.value.length != 0 )
				{
					if( !isNaN( parseInt( document.finalInventoryForm.initBalances.value ) ) && !isNaN( parseInt( document.finalInventoryForm.quantityToPull.value ) ) && !isNaN( parseInt( qtyPulled[0] ) ) )
					{
						document.finalInventoryForm.balance.value = ( parseInt( document.finalInventoryForm.initBalances.value ) - parseInt( document.finalInventoryForm.quantityToPull.value ) + parseInt( qtyPulled[0] ) );
					}
				}
				else
				{
					if( document.finalInventoryForm.actualCsLineItemId.value == -1 )
					{
						if( !isNaN( parseInt( document.finalInventoryForm.initBalances.value ) ) && !isNaN( parseInt( qtyPulled[0] ) ) )
						{
							document.finalInventoryForm.balance.value = parseInt( document.finalInventoryForm.initBalances.value ) + parseInt( qtyPulled[0] );
						}
					}
					else
					{
						if( !isNaN( parseInt( document.finalInventoryForm.initBalances.value ) ) )
						{
							document.finalInventoryForm.balance.value = parseInt( document.finalInventoryForm.initBalances.value );
						}
					}

					var hiddenQtyPull = document.finalInventoryForm.quantityToPullHidden.value.trim();

					if ( ( hiddenQtyPull.length != null ) && ( !isNaN ( parseInt (hiddenQtyPull ) ) ) )
					{
						if( !isNaN( parseInt( document.finalInventoryForm.initBalances.value ) ) && !isNaN( parseInt( hiddenQtyPull ) ) )
						{
							document.finalInventoryForm.balance.value = parseInt( document.finalInventoryForm.initBalances.value ) + parseInt( hiddenQtyPull );
						}
					}
				}
			}
		}
		else
		{
			for ( var i=0; i < document.finalInventoryForm.quantityToPull.length; i++ )
			{
				if ( firstTimeCalcBalance )
				{
					if ( document.finalInventoryForm.quantityToPull[i].value.length != 0 )
					{
						qtyPulled[i] = document.finalInventoryForm.quantityToPull[i].value;
					}
					else
					{
						qtyPulled[i] = 0;
					}
                    //alert(" qtyPulled[i] " + document.finalInventoryForm.initBalances[i].value);
					document.finalInventoryForm.balance[i].value = document.finalInventoryForm.initBalances[i].value;
				}
				else
				{
					if ( document.finalInventoryForm.quantityToPull[i].value.length != 0 )
					{
						// this condition is added By Ravikanth on 04-05-2004
						// needs to checked when the Lot is completly drawn
						if( document.finalInventoryForm.initBalances[i].value.length != 0 )
						{
							document.finalInventoryForm.balance[i].value = ( parseInt( document.finalInventoryForm.initBalances[i].value ) -
																		 parseInt( document.finalInventoryForm.quantityToPull[i].value ) + parseInt( qtyPulled[i] ) );
						}
					}
					else
					{
						if( document.finalInventoryForm.actualCsLineItemId.value == -1 )
						{
							// this condition is added By Ravikanth on 04-05-2004
							if( !isNaN( parseInt( document.finalInventoryForm.initBalances[i].value)) && !isNaN( parseInt( qtyPulled[i] ) ) )
							{
								document.finalInventoryForm.balance[i].value = parseInt( document.finalInventoryForm.initBalances[i].value ) + parseInt( qtyPulled[i] );
							}
						}
						else
						{
							// this condition is added By Ravikanth on 04-05-2004
							if( !isNaN ( parseInt( document.finalInventoryForm.initBalances[i].value ) ) )
							{
								document.finalInventoryForm.balance[i].value = parseInt( document.finalInventoryForm.initBalances[i].value );
							}
						}
						var hiddenQtyPull = document.finalInventoryForm.quantityToPullHidden[i].value.trim();
						if ( ( hiddenQtyPull.length != null ) && ( !isNaN ( parseInt (hiddenQtyPull ) ) ) )
						{
							// this condition is added By Ravikanth on 04-05-2004
							if( !isNaN( parseInt( document.finalInventoryForm.initBalances[i].value )) && !isNaN( parseInt( hiddenQtyPull )))
							{
								document.finalInventoryForm.balance[i].value = parseInt( document.finalInventoryForm.initBalances[i].value ) + parseInt( hiddenQtyPull );
							}
						}
					}
				}
			}

			if ( firstTimeCalcBalance )
			{
				firstTimeCalcBalance = false;
			}
		}
	}
}

function addQuantity( lotIndex )
{
    document.finalInventoryForm.txtErrMsg.value = "";

    var maxQtyToPull = 0;
    var sum = 0;
    var index = 0;

    var formN           = document.finalInventoryForm;
	var qtyToPullObj    = formN.quantityToPull;
    var lotIdObj        = formN.lotId;
	var qtyInObj        = formN.hdnQuantityIn;
	var qtyToPullV      = qtyToPullObj.value;
    var lotEnteredByObj = formN.lotEnteredBy;

    if (document.finalInventoryForm.quantityToPull.length == null)
    {
        if ( lotIdObj.value == -1 )
		{
            if ( parseInt ( qtyToPullObj.value ) > parseInt ( qtyInObj.value ) )
            {
               document.finalInventoryForm.txtErrMsg.value='Quantity In should be greater than Quantity Pulled';
               formN.quantityToPull.value="";
            }
            else
            {
                qtyPulled[0] = qtyInObj.value
            }
        }
        if (document.finalInventoryForm.initBalances.value < 0)
        {
            maxQtyToPull = qtyPulled[0];
        }
        else
        {
            maxQtyToPull = parseInt( document.finalInventoryForm.initBalances.value ) + parseInt( qtyPulled[0] );
        }

		if( !isNaN ( parseInt( document.finalInventoryForm.quantityToPull.value ) ) && !isNaN( maxQtyToPull ) )
		{
            if(  parseInt( document.finalInventoryForm.quantityToPull.value ) <= maxQtyToPull )
            {
                sum = parseInt ( document.finalInventoryForm.quantityToPull.value );
            }
            else
            {
                if ( lotEnteredByObj.value == '0' )
                {
                    document.finalInventoryForm.txtErrMsg.value='Quantity should be less than or equal to balance ' + maxQtyToPull;
                    document.finalInventoryForm.quantityToPull.value="";
                }
                else
                {
                    sum = parseInt ( document.finalInventoryForm.quantityToPull.value );
                }
            }
		}
    }
    else
    {
        for ( var i=0; i < document.finalInventoryForm.quantityToPull.length; i++ )
        {
            if ( document.finalInventoryForm.quantityToPull[i].value.length != 0 )
            {
                if ( lotIdObj[i].value == -1 )
                {
                    if ( parseInt ( qtyToPullObj[i].value ) > parseInt ( qtyInObj[i].value ) )
                    {
                       document.finalInventoryForm.txtErrMsg.value='Quantity In should be greater than Quantity Pulled';
                       formN.quantityToPull[i].value="";
                    }
                    else
                    {
                        qtyPulled[i] = qtyInObj[i].value
                    }
                }
                if ( document.finalInventoryForm.initBalances[i].value < 0 )
                {
                    maxQtyToPull = qtyPulled[i];
                }
                else
                {
                    maxQtyToPull = parseInt( document.finalInventoryForm.initBalances[i].value ) + parseInt( qtyPulled[i] );
                }
                //alert(" maxQtyToPull = " + maxQtyToPull  + " quantityToPull = " + parseInt ( document.finalInventoryForm.quantityToPull[i].value ));
				if( !isNaN ( parseInt( document.finalInventoryForm.quantityToPull[i].value ) )  && !isNaN( maxQtyToPull )  )
				{
                    if( parseInt( document.finalInventoryForm.quantityToPull[i].value ) <= maxQtyToPull )
                    {
                        sum += parseInt ( document.finalInventoryForm.quantityToPull[i].value );
                        index=i;
                    }
                    else
                    {   if ( lotEnteredByObj[i].value == '0' )
                        {
                            document.finalInventoryForm.txtErrMsg.value='Quantity should be less than or equal to balance ' + maxQtyToPull;
                            document.finalInventoryForm.quantityToPull[i].value="";
                            index=i;
                        }
                        else
                        {
                            sum += parseInt ( document.finalInventoryForm.quantityToPull[i].value );
                            index=i;
                        }
                    }
				}
            }
        }
    }
	var tempTotal = document.finalInventoryForm.totals.value;
	document.finalInventoryForm.totals.value = sum;

    if ( parseInt( requestedQty ) < parseInt( sum ) )
    {
        if ( document.finalInventoryForm.quantityToPull.length == null )
        {
            document.finalInventoryForm.quantityToPull.value = tempTotal;
            document.finalInventoryForm.totals.value = tempTotal;
        }
		else
		{
			var faultyQtyToPull = 0;
			for (var counts = 0; counts < document.finalInventoryForm.quantityToPull.length; counts++ )
			{
				if ( (document.finalInventoryForm.quantityToPull[counts].value.length != 0 ) && ( counts != lotIndex ) )
				{
					faultyQtyToPull += parseInt(document.finalInventoryForm.quantityToPull[counts].value);
				}
			}
			faultyQtyToPull = parseInt (tempTotal) - parseInt (faultyQtyToPull );
            document.finalInventoryForm.quantityToPull[lotIndex].value = faultyQtyToPull;
			document.finalInventoryForm.totals.value=tempTotal;
        }
        document.finalInventoryForm.txtErrMsg.value='Total should be less than or equal to Quantity to be shipped';
    }

    else
    {
        calcDynValues();
    }
}

function resetValues()
{
    document.finalInventoryForm.reset();
    document.finalInventoryForm.qtyTobeShipped.value = initQtyToBeShipped;
    document.finalInventoryForm.totals.value = initTotalQtyPulled;
}

///////////////////////////////////////////////////////////////////////////////////////////////

var dateElement = "";
function openCalendar(dateValue)
{
    dateElement = dateValue;
    newWindow = window.open('<%=chipTracContext%>/jsp/includes/calendar.html','calenderPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=no,width=180,height=440,resizable=no');
    newWindow.moveTo(550,180);
    newWindow.focus();
}
function assignDate(passedValue)
{
    dateElement.value=passedValue;
    window.focus();
}

/*
	There is a gamble in this function, we are setting the locationId to shippingFromAddressId
	value as we are not having the LocationId parameter for new Lots.
*/

function addMore( partNumber, locationId, csLineItemId )
{
    var index  = 0;
    index =  parseInt( document.finalInventoryForm.noOfLots.value );
    var htmltext = '';
    var tab = document.getElementById( "lineItemsTable" );
    var newRowIndex = document.getElementById( "rowIndex" ).rowIndex;
    var newRow = tab.insertRow( newRowIndex );

    var newCell = newRow.insertCell();
    newCell.style.backgroundColor = "#DEE1E2";
    newCell.align = "center";
    newCell.width = "20%";
    htmltext = '<font class="NArialL">' + partNumber + '</font>';
    htmltext = htmltext + '&nbsp;<input type="hidden" name="mktPartNumber" value="' + partNumber +'">';
    newCell.innerHTML = htmltext;
    <%if( ConfigManager.getShowFabLotNumberInPackingSlip() )
    { %>
    newCell = newRow.insertCell ();
    newCell.style.backgroundColor = "#DEE1E2";
    htmltext = '<input type="text" name="fabLotNumber" maxLength="13" size="15" value="" class="valuetxfield">';
    newCell.innerHTML = htmltext;
    <%}%>
    newCell = newRow.insertCell ();
    newCell.style.backgroundColor = "#DEE1E2";
    htmltext = '<input type="text" name="lotNumber" size="13" maxLength="50" value="" class="valuetxfield" >';
    htmltext = htmltext + '&nbsp;<input type="hidden" name="locationId" value="' + locationId + '">';
    htmltext = htmltext + '<input type="hidden" name="balance" value="0">';
    htmltext = htmltext + '<input type="hidden" name="lotId" value="-1">';
    <%if( !ConfigManager.getShowFabLotNumberInPackingSlip() )
    {%>
     htmltext = htmltext + '<input type="hidden" name="fabLotNumber" value="">';
    <%}%>

    newCell.innerHTML = htmltext;

    newCell = newRow.insertCell ();
    newCell.style.backgroundColor = "#DEE1E2";
    htmltext = '<input type="text" name="dateCode" maxLength="10" size="10" value="" class="valuetxfield">';
    newCell.innerHTML = htmltext;

    newCell = newRow.insertCell ();
    newCell.style.backgroundColor = "#DEE1E2";
    htmltext = '<table cellspacing="0" cellpadding="0" valign="top" width="100%">';
    htmltext = htmltext + '<tr><td   valign="top" align="left">&nbsp;<input type="text" name="dateIn" maxLength="10" size="12" value="" class="valuetxfield">';
    htmltext = htmltext + '&nbsp;&nbsp;<a href="javascript:if(document.finalInventoryForm.dateIn.length!=null){openCalendar(document.finalInventoryForm.dateIn[' + index + '])}else{openCalendar(document.finalInventoryForm.dateIn)}">';
    htmltext = htmltext + '<img border="0" src="<%=chipTracContext%>/jsp/includes/images/date_selector.gif" height="16" width="20"></img></a></td>';
    htmltext = htmltext + '</tr></table>';
    newCell.innerHTML = htmltext;

    newCell = newRow.insertCell ();
    newCell.style.backgroundColor = "#DEE1E2";
    htmltext = '&nbsp;<input type="text" size="10" name="hdnQuantityIn" maxLength="10" value="" class="valuetxfield" onkeypress="javascript:numericFieldKeyPress( this )" onblur="addQuantity('+ index +')">';
    htmltext = htmltext + '<input type="hidden" name=initBalances value="0" >';
    newCell.innerHTML = htmltext;

    newCell = newRow.insertCell ();
    newCell.style.backgroundColor = "#DEE1E2";
    newCell.align = "center";
    htmltext = '<input type="text"  size="8" name="quantityToPull"  onkeyup="addQuantity(' + index + ')" onkeypress="javascript:numericFieldKeyPress( this )"  value="" class="valuetxfield">';
    htmltext = htmltext + '<input type="hidden" name="quantityToPullHidden" value="0" >';
    htmltext = htmltext + '<input type="hidden" name="csLineItemId" value="'+ csLineItemId +'">';
    htmltext = htmltext + '<input type="hidden" name="lotEnteredBy" value="0">';
    htmltext = htmltext + '<input type="hidden" name="lotBalanceQty" value="0">';
    newCell.innerHTML = htmltext;

    <%
     if (reqFromVendorInterface == null )
     {
   %>
        newCell = newRow.insertCell ();
        newCell.style.backgroundColor = '#DEE1E2';
        newCell.className = 'NArialL';
        htmltext = '<input type="checkbox" name="isReduceBal" checked="true">(DataEntry)';
        newCell.innerHTML = htmltext;
    <%}%>
    document.finalInventoryForm.noOfLots.value = index + 1;
}
function setQuantyties( index )
{
	var form	= document.finalInventoryForm;
	var qtyInObject;
	var qtyPullObject;
	var hdnQuantityInObject;
	var initBalancesObject;
	var quantityToPullObject;
	var quantityToPullHiddenObject;

	var qtyIn;
	var qtyPull;

	if( typeof form.hdnQuantityIn.length == 'undefined' )
	{
		qtyInObject = form.hdnQuantityIn;
		qtyPullObject = form.quantityToPull;
		hdnQuantityInObject = form.hdnQuantityIn;
		initBalancesObject	= form.initBalances;
		quantityToPullHiddenObject = form.quantityToPullHidden;
	}
	else
	{
		qtyInObject = form.hdnQuantityIn[ index ];
		qtyPullObject = form.quantityToPull[ index ];
		hdnQuantityInObject = form.hdnQuantityIn[ index ];
		initBalancesObject	= form.initBalances[ index ];
		quantityToPullHiddenObject = form.quantityToPullHidden[ index ];
	}

	qtyIn	= qtyInObject.value;
	qtyPull = qtyPullObject.value;

	if( qtyIn.length > 0 && isNaN ( parseInt( qtyIn ) ) )
	{
		hdnQuantityInObject.value = "";
		hdnQuantityInObject.focus();
	}
	else if( qtyIn < qtyPull )
	{
		form.initBalances[ index ].value = 0;
		form.quantityToPull[ index ].value = 0;
		calcBalance();
	}
	else
	{
		initBalancesObject.value = parseInt( qtyIn );
		//form.initBalances[ index ].value = parseInt( qtyIn );
		//form.quantityToPullHidden[ index ].value = 0;
		quantityToPullHiddenObject.value = 0;
		if ( document.finalInventoryForm.quantityToPull.length == null )
		{
			qtyPulled[0] = 0;
		}
		else
		{
			qtyPulled[index] = 0;
			for ( var i = 0; i < document.finalInventoryForm.quantityToPull.length; i++ )
			{
				if ( qtyPulled[i] != 0 )
				{
					qtyPulled[i] = qtyPulled[i];
				}
				else
				{
					qtyPulled[i] = 0;
				}
			}
		}
		calcBalance();
	}
}

var requestedQty;
requestedQty = parseInt('<%=quantityToBeShipped%>');
function saveData() {

    document.finalInventoryForm.txtErrMsg.value = "";
	var index = <%=txtIndex%>;
    var sum = 0;
    var flag = 0;
	var msg = '';

	if ( document.finalInventoryForm.quantityToPull != null )
	{
		if( document.finalInventoryForm.dropShip.value == 'true' )
		{
			trimValues();
			// Check For Duplicate LotNumbers
			msg = checkForDulicateLotNumbers();

			if( msg.length == 0 )
			{
				// Check if LotNumber is given for every New Lot where the Quantity is Pulled
				msg = checkForEmptyLotNumbers();
			}

			if( msg.length == 0 )
			{
				// Check if LotNumber is given for every New Lot where the Quantity is Pulled
				msg = checkForValidDate();
			}

			if( msg.length > 0 )
			{
				document.finalInventoryForm.txtErrMsg.value = msg;
				return;
			}
		}
		if ( document.finalInventoryForm.quantityToPull.length == null )
		{
			if( checkInteger( document.finalInventoryForm.quantityToPull.value, "Quantity Pull", "N" ) == false )
			{
				 document.finalInventoryForm.txtErrMsg.value = errMsg;
				 document.finalInventoryForm.quantityToPull.focus();
				 flag = 1;
			}
			else
			{
				sum = document.finalInventoryForm.quantityToPull.value.trim();

				if( sum.length == 0 )
				{
					sum = 0;
				}

				<% if( isRequestFromTrackingNoPage != null && isRequestFromTrackingNoPage.length() > 0 ) { %>
				    var fieldValue  =  window.opener.document.shippingAdviseForm[ 'lineitems[' + index +'].qtyPulled'];
                    var fieldValue1 =  window.opener.document.shippingAdviseForm[ 'lineitems[' + index +'].inventoryPulled'];
                    if(sum != requestedQty )
                    {
                        document.finalInventoryForm.txtErrMsg.value='Please pull all Total Quantity to be Shipped';
                        return;
                    }
                <% } else { %>
				    var fieldValue  =  window.opener.document.packingSlipForm[ 'lineitems[' + index +'].qtyPulled'];
                    var fieldValue1 =  window.opener.document.packingSlipForm[ 'lineitems[' + index +'].inventoryPulled'];
                    if( sum != requestedQty )
                    {
                        document.finalInventoryForm.txtErrMsg.value='Please pull all Total Quantity to be Shipped';
                        return;
                    }
                <% } %>
				fieldValue.value  = sum;	// This sets the value for the Quantity Pulled
				fieldValue1.value = sum;	// This sets the value for the Inventory Pulled.
											// This is required for DropShipment To check wether the Qty is pulled from Inventory Screen

				if( parseInt( requestedQty ) < parseInt( document.finalInventoryForm.totals.value ) )
				{
					document.finalInventoryForm.txtErrMsg.value='Total should be less than or equal to Quantity to be shipped';
				}
				else
				{
                    if( typeof document.finalInventoryForm.isReduceBal != "undefined" )
                    {
                        if( document.finalInventoryForm.isReduceBal.checked )
                        {
                            document.finalInventoryForm.isReduceBal.value = "reduceBalance"
                        }
                        else
                        {
                            document.finalInventoryForm.isReduceBal.checked = true
                        }
                    }
					document.finalInventoryForm.totals.disabled = false;
					document.finalInventoryForm.qtyTobeShipped.disabled = false;
                    addOptionElementForParentWindow(index);
					document.finalInventoryForm.submit();
				}
			}
		}
		else
		{
			for( var i=0; i < document.finalInventoryForm.quantityToPull.length; i++ )
			{
				if (document.finalInventoryForm.quantityToPull[i].value.length != 0)
				{
					if(checkInteger(document.finalInventoryForm.quantityToPull[i].value,"Quantity Pull","N")==false)
					{
						 document.finalInventoryForm.txtErrMsg.value=errMsg;
						 document.finalInventoryForm.quantityToPull[i].focus();
						 flag=1;
						 break;
					}
					else
					{
						if (document.finalInventoryForm.quantityToPull[i].value.length != 0)
						{
							sum += parseInt (document.finalInventoryForm.quantityToPull[i].value.trim());
						}
					}

                    if ( document.finalInventoryForm.dateCode[i].value =='0')
                    {
                       if ( document.finalInventoryForm.dateCode1[i].value == '' )
                       {
                           document.finalInventoryForm.txtErrMsg.value= "Please enter new Date Code";
                           document.finalInventoryForm.dateCode1[i].focus();
                           return;
                       }

                   }
                   if ( document.finalInventoryForm.dateCode[i].value =='-1')
                   {
                       document.finalInventoryForm.txtErrMsg.value="Please select Date Code";
                       document.finalInventoryForm.dateCode[i].focus();
                       return;
                   }
				}
			}
			if(flag==0)
			{
				if( sum.length == 0 )
				{
					sum = 0;
				}
				<% if( isRequestFromTrackingNoPage != null && isRequestFromTrackingNoPage.length() > 0 ) { %>
                    var fieldValue =  window.opener.document.shippingAdviseForm[ 'lineitems[' + index +'].qtyPulled'];
                    var fieldValue1 =  window.opener.document.shippingAdviseForm[ 'lineitems[' + index +'].inventoryPulled'];
                    if(sum != requestedQty )
                    {
                        document.finalInventoryForm.txtErrMsg.value='Please pull all Total Quantity to be Shipped';
                        return;
                    }
                <% } else { %>
				    var fieldValue =  window.opener.document.packingSlipForm[ 'lineitems[' + index +'].qtyPulled'];
                    var fieldValue1 =  window.opener.document.packingSlipForm[ 'lineitems[' + index +'].inventoryPulled'];
                    if( sum != requestedQty )
                    {
                        document.finalInventoryForm.txtErrMsg.value='Please pull all Total Quantity to be Shipped';
                        return;
                    }
                <% } %>
				fieldValue.value  = sum;
				fieldValue1.value = sum;
				if( parseInt( requestedQty ) < parseInt( document.finalInventoryForm.totals.value ) )
				{
					document.finalInventoryForm.txtErrMsg.value='Total should be less than or equal to Quantity to be shipped';
				}
				else
				{
                    for( var i = 0; i < document.finalInventoryForm.quantityToPull.length; i++ )
			        {
                        //alert(i + " Chk = " + document.finalInventoryForm.isReduceBal[i].checked + " LotNo = "  + document.finalInventoryForm.lotNumber[i].value);
                        if( typeof document.finalInventoryForm.isReduceBal != "undefined" )
                        {
                            if( document.finalInventoryForm.isReduceBal[i].checked )
                            {
                                document.finalInventoryForm.isReduceBal[i].value = "reduceBalance"
                            }
                            else
                            {
                                document.finalInventoryForm.isReduceBal[i].checked = true
                            }
                        }
                    }
					document.finalInventoryForm.totals.disabled = false;
					document.finalInventoryForm.qtyTobeShipped.disabled = false;
                    addOptionElementForParentWindow(index);

                    document.finalInventoryForm.submit();
				}
			}
		}
	}
	else
	{
		window.close();
	}
}


function addOptionElementForParentWindow( index )
{

    var partNumberV = "" ;
    <% if( isRequestFromTrackingNoPage != null && isRequestFromTrackingNoPage.length() > 0 ) { %>
        var shippedPartNumberObj  =  window.opener.document.shippingAdviseForm[ 'lineitems[' + index +'].shipped_Part_Number'];
    <% } else { %>
        var shippedPartNumberObj  =  window.opener.document.packingSlipForm[ 'lineitems[' + index +'].shipped_Part_Number'];
    <% } %>

    var inventoryPulled = false;

    if (typeof document.finalInventoryForm.quantityToPull.length == "undefined" )
    {
        if (document.finalInventoryForm.quantityToPull.value.length != 0)
        {
            partNumberV = document.finalInventoryForm.mktPartNumber.value;
            if( parseInt( document.finalInventoryForm.quantityToPull.value ) > 0 )
            {
                //window.opener.deleteAllOptions(index);
                //window.opener.addOptionToSelect ( partNumberV , partNumberV , index );
                inventoryPulled = true;
            }
        }
    }
    else
    {
        if (document.finalInventoryForm.quantityToPull.length > 0)
        {
            //window.opener.deleteAllOptions(index);
        }
        for( var i=0; i < document.finalInventoryForm.quantityToPull.length; i++ )
        {
            if (document.finalInventoryForm.quantityToPull[i].value.length != 0)
            {
                partNumberV = document.finalInventoryForm.mktPartNumber[i].value;
                if( parseInt( document.finalInventoryForm.quantityToPull[i].value ) > 0 )
                {
                    //window.opener.addOptionToSelect ( partNumberV , partNumberV , index );
                    //shippedPartNumberObj.disabled = true;
                    inventoryPulled = true;
                }
            }
        }
    }

    if(inventoryPulled)
        shippedPartNumberObj.disabled = true;
    else
        shippedPartNumberObj.disabled = false;

    //window.opener.chjIndexAndaddOptionToSelect(index);
}

var initTotalQtyPulled;
var initQtyToBeShipped;
var firstTimeCalcQty = true;
var requestedQty;

function calcQtyToBeShipped()
{
	// This condition is added by ravikanth on 08-05-2004
	// Because in drop shipment there can be a condition where there are no lots for the PartNumber
	if( typeof document.finalInventoryForm.quantityToPull != 'undefined'  )
	{

		if ( document.finalInventoryForm.quantityToPull.length == null )
		{

			var sum = 0;
			if ( document.finalInventoryForm.quantityToPull.value.length != 0 )
			{
				sum = document.finalInventoryForm.quantityToPull.value;
			}
			if( firstTimeCalcQty == true )
			{
				if( document.finalInventoryForm.actualCsLineItemId.value == -1 )
				{
					requestedQty = parseInt('<%=quantityToBeShipped%>');
				}
				else
				{
					// Condition added By Ravikanth on 05-05-2004
					if( document.finalInventoryForm.dropShip.value == 'true' )
					{
						requestedQty = parseInt('<%=quantityToBeShipped%>');
					}
					else
					{
						requestedQty = parseInt( parseInt('<%=quantityToBeShipped%>') + parseInt(sum) );
					}
				}
				initQtyToBeShipped = ( requestedQty - sum );
				initTotalQtyPulled = sum;

				firstTimeCalcQty = false;
			}

			document.finalInventoryForm.qtyTobeShipped.value = requestedQty - sum ;
		}
		else
		{
			var sum = 0;
			for( var i=0; i < document.finalInventoryForm.quantityToPull.length; i++ )
			{
				if ( document.finalInventoryForm.quantityToPull[i].value.length != 0 )
				{
					sum += parseInt ( document.finalInventoryForm.quantityToPull[i].value );
				}
			}

			if( firstTimeCalcQty == true )
			{
				if( document.finalInventoryForm.actualCsLineItemId.value == -1 )
				{
					requestedQty = parseInt('<%=quantityToBeShipped%>');
				}
				else
				{
					// Condition added By Ravikanth on 05-05-2004
					if( document.finalInventoryForm.dropShip.value == 'true' )
					{
						requestedQty = parseInt('<%=quantityToBeShipped%>');
					}
					else
					{
						requestedQty = parseInt('<%=quantityToBeShipped%>') + parseInt( sum );
					}
				}

				initQtyToBeShipped = (requestedQty - sum);
				initTotalQtyPulled = sum;

				firstTimeCalcQty = false;
			}

			document.finalInventoryForm.qtyTobeShipped.value = (requestedQty - sum);
		}
	}
	else
	{
		var sum = 0;
		requestedQty = parseInt('<%=quantityToBeShipped%>');
		initQtyToBeShipped = (requestedQty - sum);
		initTotalQtyPulled = sum;
		firstTimeCalcQty = false;
		document.finalInventoryForm.qtyTobeShipped.value = (requestedQty - sum);
	}

}


function trimValues()
{
	form = document.finalInventoryForm;
	if( typeof form.lotId.length == 'undefined' )
	{
		form.lotNumber.value = form.lotNumber.value.trim();
		form.dateIn.value = form.dateIn.value.trim();
		form.dateCode.value = form.dateCode.value.trim();
	}
	else
	{
		for( var i = 0; i < form.lotId.length; i++ )
		{
			if( form.lotId[i].value == -1 )
			{
				form.lotNumber[i].value	= form.lotNumber[i].value.trim();
				form.dateIn[i].value	= form.dateIn[i].value.trim();
				form.dateCode[i].value	= form.dateCode[i].value.trim();
			}
		}
	}
}

function checkForDulicateLotNumbers()
{
	form = document.finalInventoryForm;
	msg = "";

	if( typeof form.lotNumber.length == 'undefined' )
	{
	}
	else
	{
		var lotNumbers = new Array( parseInt( form.noOfLots.value ) );
        var partNumbers = new Array( parseInt( form.noOfLots.value ) );
		for( var i = 0; i < parseInt( form.noOfLots.value ); i++ )
		{
			lotNumbers[i] = form.lotNumber[i].value;
            partNumbers[i] = form.mktPartNumber[i].value;
		}

		for( var i = 0; i < lotNumbers.length - 1; i++ )
		{
			for( var j = i + 1; j < lotNumbers.length; j++ )
			{
				if( lotNumbers[i].length > 0 && lotNumbers[j].length > 0 )
				{
					if( lotNumbers[i] == lotNumbers[j] && partNumbers[i] == partNumbers[j]  )
					{
						msg = msg + ' ' + lotNumbers[i];
					}
				}
			}
		}
	}

	if( msg.length > 0 )
	{
		msg = 'Duplicate Lot Numbers cannot be entered '+ msg;
	}
	return msg;
}

function checkForEmptyLotNumbers()
{
	form = document.finalInventoryForm;
	msg = "";
    document.finalInventoryForm.txtErrMsg1.value='';

	if( typeof form.lotNumber.length == 'undefined' )
	{
		//form.lotNumber.value = form.lotNumber.value.trim();
		if( ( ( form.quantityToPull.value.length > 0 && form.quantityToPull.value != '0' ) || ( form.hdnQuantityIn.value.length > 0 && form.hdnQuantityIn.value != '0' ) ) && form.lotNumber.value.length < 1 )
		{
			form.lotNumber.focus();
			msg = 'Lot Number cannot be Empty';
		}
        if ( form.lotNumber.type == "text" )
        {
            if( alphanumSpecial( form.lotNumber.value,"Lot Number " + form.lotNumber.value ,"N") == false )
            {
                msg = errMsg ;
            }
            if( alphanumSpecial( form.dateCode.value,"Date Code " + form.dateCode.value ,"N") == false )
            {
                msg = " Please enter valid Date Code " + form.dateCode.value ;
            }
            if( form.lotNumber.value.length > 0 )
            {
                if(chkDate(form.dateIn.value,"Date In "  + form.dateIn.value,"Y")==false)
                {
                    msg = " Please enter valid Date In " + form.dateIn.value ;
                }
                if(chkCurrency(form.hdnQuantityIn.value,"Quantity In","Y")==false)
                {
                    msg = errMsg ;
                }
                if( parseInt( form.hdnQuantityIn.value ) == 0 )
                {
                    msg = "Quantity In should be greater than zero" ;
                }
            }
        }
	}
	else
	{
		for( var i = 0; i < form.lotNumber.length; i++ )
		{
			//form.lotNumber[i].value = form.lotNumber[i].value.trim();
			if( ( ( form.quantityToPull[i].value.length > 0 && form.quantityToPull[i].value != '0' ) || ( form.hdnQuantityIn[i].value.length > 0 && form.hdnQuantityIn[i].value != '0' ) ) && form.lotNumber[i].value.length < 1 )
			{
				form.lotNumber[i].focus();
				msg = 'Lot Number cannot be empty';
				break;
			}
            if ( form.lotNumber[i].type == "text" )
            {
                if( alphanumSpecial( form.lotNumber[i].value,"Lot Number " + form.lotNumber[i].value ,"N") == false )
                {
                    msg = errMsg ;
                    break;
                }
                if( alphanumSpecial( form.dateCode[i].value,"Date Code " + form.dateCode[i].value ,"N") == false )
                {
                    msg = " Please enter valid Date Code " + form.dateCode[i].value ;
                    break;
                }
                if( form.lotNumber[i].value.length > 0 )
			    {
                    if(chkDate(form.dateIn[i].value,"Date In "  + form.dateIn[i].value,"Y")==false)
                    {
                        msg = " Please enter valid Date In " + form.dateIn[i].value ;
                        break;
                    }
                    if(chkCurrency(form.hdnQuantityIn[i].value,"Quantity In","Y")==false)
                    {
                        msg = errMsg ;
                        break;
                    }
                    if( parseInt( form.hdnQuantityIn[i].value ) == 0 )
			        {
                        msg = "Quantity In should be greater than zero" ;
                        break;
                    }

                    /*if( form.quantityToPull[i].value.length > 0 &&  form.hdnQuantityIn[i].value.length > 0 )
			        {
                        if( parseInt( form.quantityToPull[i].value ) > parseInt( form.hdnQuantityIn[i].value ) )
                        {
                            msg = "Quantity In should be greater than Quantity Pulled" ;
                            break;
                        }
                    } */

                }

            }
		}
	}
	return msg;
}

function checkForValidDate()
{
	msg = "";

	if( typeof document.finalInventoryForm.dateIn.length == 'undefined' )
	{
		if( ( ( document.finalInventoryForm.quantityToPull.value.length > 0 && document.finalInventoryForm.quantityToPull.value != '0' ) || ( document.finalInventoryForm.hdnQuantityIn.value.length > 0 && document.finalInventoryForm.hdnQuantityIn.value != '0' ) )&& document.finalInventoryForm.dateIn.value.length > 0   && document.finalInventoryForm.lotId.value == -1 )
		{
			//document.finalInventoryForm.dateIn.value = document.finalInventoryForm.dateIn.value.trim();
			if( chkDate( document.finalInventoryForm.dateIn.value, "Date In", "Y" ) == false )
			{
				document.finalInventoryForm.dateIn.focus();
				msg = 'Please enter a valid Date for Date In';
			}
		}
	}
	else
	{
		for( var i = 0; i < document.finalInventoryForm.dateIn.length; i++ )
		{
			if( ( ( document.finalInventoryForm.quantityToPull[i].value.length > 0 && document.finalInventoryForm.quantityToPull[i].value != '0' ) || ( document.finalInventoryForm.hdnQuantityIn[i].value.length > 0 && document.finalInventoryForm.hdnQuantityIn[i].value != '0' ) )&& document.finalInventoryForm.dateIn[i].value.length > 0   && document.finalInventoryForm.lotId[i].value == -1 )
			{
				//document.finalInventoryForm.dateIn[i].value = document.finalInventoryForm.dateIn[i].value.trim();
				if( chkDate( document.finalInventoryForm.dateIn[i].value, "Date In", "Y" ) == false )
				{
					document.finalInventoryForm.dateIn[i].focus();
					msg = 'Please enter a valid Date for Date In';
					break;
				}
			}
		}
	}
	return msg;
}

function enableDateCodeField( index )
{
    var form = document.finalInventoryForm;

    if( form.dateCode[index].value == '0' )
    {
        form.dateCode1[index].style.display = 'block';
    }
    else
    {
       form.dateCode1[index].style.display = 'none';
    }

}
</SCRIPT>
<BODY bgcolor="ffffff" marginheight="0" marginwidth="0" topmargin=0 leftmargin=0>

<% if ( closeWindowAfterSessionTimeOut == null ) { %>

<table align="center" border="0" width="90%" id="lineItemsTable">

<html:form name="finalInventoryForm" type="com.scalar.chiptrack.ChipTrackActionForm" method="post" action="/finalInventory.do?action=save">
    <tr>
        <td width="100%" colspan='7'>
            <input type="hidden" name="lineItemId" value='<%=request.getAttribute ("lineItemId")%>'/>
            <input type="hidden" name="fieldName" value='<%=request.getParameter ("fieldName")%>'/>
            <input type="hidden" name="fieldName1" value='<%=request.getParameter ("fieldName1")%>'/>
            <input type="hidden" name="actualCsLineItemId" value='<%=request.getParameter ("csLineItemId")%>'/>
            <input type="hidden" name="dropShip" value='<%=request.getParameter ("dropShip")%>'/>
            <chiptrack:errors styleClass="NArialL"/>
            <% if (reqFromVendorInterface == null ) { %>
                <br><font class="NArialL"><font color="blue">Vendor might have pulled inventory from below Lots</font></font>
            <% } else if (reqFromVendorInterface != null && issuedPackingSlip == true && modifyInventory == false ) { %>
                <br><font class="NArialL"><font color="blue"><%=Constants.NO_MODIFY_RIGHTS %></font></font>
            <% } %>
        </td>
    </tr>
    <tr>
        <td width="100%" colspan='7'>
            <INPUT align=left border=0 maxLength=100 name="txtErrMsg" size=100 style="BORDER-BOTTOM: thin; BORDER-LEFT-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-TOP: thin; CLEAR: none; COLOR: red;font-family: arial;font-size: 10pt;font-weight:bold " value="" readOnly>
            <INPUT align=left border=0 maxLength=100 name="txtErrMsg1" size=100 style="BORDER-BOTTOM: thin; BORDER-LEFT-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-TOP: thin; CLEAR: none; COLOR: red;font-family: arial;font-size: 10pt;font-weight:bold " value="" readOnly>
        </td>
    </tr>
    <tr>
        <td width="100%" colspan='7' align='center'><font class="NArialL">Inventory Selection Screen</font></td>
    </tr>
	<tr>
        <td align="center" bgcolor="#993333" width="20%" class="NArialL"><font color="#FFFFFF"><bean:message key="label.mfgPartNumber"/></font></td>
        <%
        if( ConfigManager.getShowFabLotNumberInPackingSlip() )
        {
        %>
        <td align="center" bgcolor="#993333" width="20%" class="NArialL"><font color="#FFFFFF">Fab Lot No</font></td>
        <% } %>
        <td align="center" bgcolor="#993333" width="20%" class="NArialL"><font color="#FFFFFF">Lot No<font color="RED" size="1"><B>*</B></font></font></td>
        <td align="center" bgcolor="#993333" width="10%" class="NArialL"><font color="#FFFFFF">Date Code</font>&nbsp;</td>
        <td align="center" bgcolor="#993333" width="20%" class="NArialL"><font color="#FFFFFF">Date In<font color="RED" size="1"><B>*</B></font></font>&nbsp;</td>
        <td align="center" bgcolor="#993333" width="10%" class="NArialL"><font color="#FFFFFF">Quantity In<font color="RED" size="1"><B>*</B></font></font>&nbsp;</td>
        <td align="center" bgcolor="#993333" width="10%" class="NArialL"><font color="#FFFFFF"><%if (viewOnly) out.print ("Qty Pulled"); else out.print ("Quantity to Pull");%></font></td>
        <% if (reqFromVendorInterface == null ) { %> <td align="center" bgcolor="#993333" width="10%" class="NArialL"><font color="#FFFFFF">Reduce Balance(Source)</font></td> <% } %>
    </tr>

    <%
        int totalQtyPull = 0;
        if ((finalInventoryDataList == null) || (finalInventoryDataList.isEmpty() == true))
        {
    %>
    <tr id="rowIndex"><td width="100%" colspan='11'>&nbsp;<font id='font1'></font></td></tr>
    <tr>
        <%
            if( parentPartNoExitsInSubs == true ) {
                if( ! request.getParameter( "viewonly" ).equalsIgnoreCase( "true" ) ) { %>
        <td width="100%" colspan="7" align="right">
           <font class='NArialL'><a href="javascript:addMore('<%=request.getParameter ("parentPartNo")%>', '<%=request.getParameter ("shippingFromAddressId")%>', '<%=request.getParameter ("csLineItemId")%>');" onmouseover="window.status='Click here to add new lot';return true" onmouseout ="window.status='';return true" >Click here to add new Lot</a></font>
           <input type="hidden" name="noOfLots" value='0'/>
        </td>
        <% } } else { %>
        <td width="100%" colspan="7" class="NArialL" align=center bgcolor='DEE1E2'>
            <font color="#000000">No Records Found</font>
            <input type="hidden" name="noOfLots" value='0'/>
        </td>
       <% } %>
	</tr>
	<tr>
        <td width="100%" colspan='7'>
            <table width="100%" border="0">
                <tr>
                    <td align='right'><font class='NArialL'>Total Quantity to be Shipped:</font></td>
                    <td><input type="text" size='4' name="qtyTobeShipped" class='NArialL' style="BORDER-BOTTOM: thin; BORDER-LEFT-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-TOP: thin; CLEAR: none; COLOR: red;font-family: arial;font-size: 10pt;font-weight:bold " value='<%if (viewOnly) out.print (quantityToBeShipped); else out.print("");%>' readOnly disabled>
                    <%
                            if (!viewOnly)
                            {
                    %>	<script>calcDynValues();</script>
                    <%
                            }
                    %>
                    </td>
                    <td align='right'><font class='NArialL'>Total Quantity Pulled:&nbsp;&nbsp;</font></td>
                    <td><input type="text" size='4' name="totals" class='NArialL' style="BORDER-BOTTOM: thin; BORDER-LEFT-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-TOP: thin; CLEAR: none; COLOR: red;font-family: arial;font-size: 10pt;font-weight:bold " value="" readOnly disabled><script>document.finalInventoryForm.totals.value='<%=totalQtyPull%>'</script></td>
                 </tr>
            </table>
        </td>
	</tr>
	<tr>
        <td colspan='7'><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=30></td>
	</tr>
    <%
        }
        else
        {
            int size = finalInventoryDataList.size();
            FinalInventoryData finalInventoryData = null;

            String color[]		= {"DEE1E2", "FFFFEE"};
            int quantityShipped = 0;
            String processStepName = "";
            String partNumber	= "";
            String vendorName	= "";

            for ( int i = 0; i < size; i++ )
            {
                finalInventoryData = (FinalInventoryData) finalInventoryDataList.get(i);
                //if( viewOnly && finalInventoryData.getQuantityPull() <= 0 && issuedPackingSlip == false && modifyInventory == true )
                if ( reqFromVendorInterface != null )
                {
                   if( issuedPackingSlip == false && finalInventoryData.getQuantityPull() <= 0 )
                   {
                        continue;
                   }
                }
                else
                {
                    if( viewOnly && finalInventoryData.getQuantityPull() <= 0 )
                    {
                        continue;
                    }
                }

                if ( ((processStepName != null) && (processStepName.equalsIgnoreCase (finalInventoryData.getStepName()) == false)) ||
                    ((vendorName != null) && (vendorName.equalsIgnoreCase (finalInventoryData.getVendorLocation()) == false)))
                {
                    processStepName = finalInventoryData.getStepName();
                    partNumber = finalInventoryData.getMktPartNumber();
                    vendorName = finalInventoryData.getVendorLocation();
    %>
	<tr><td colspan='<% if (reqFromVendorInterface != null) out.print("7"); else out.print("8") ; %>' >&nbsp;</td></tr>
	<tr><td colspan='<% if (reqFromVendorInterface != null) out.print("7"); else out.print("8") ; %>' bgcolor="#999CCC" align='left'><font class='NArialL'><font color='#000000'>&nbsp;&nbsp;&nbsp; <%=processStepName + " - " + vendorName%> </font></font></td></tr>
    <%          } %>
	<tr bgcolor='<%=color[i%2]%>'>
		<td align="center" nowrap  width="20%">
            <font class="NArialL"><%=finalInventoryData.getMktPartNumber()%></font>
		</td>
                <%
                if( ConfigManager.getShowFabLotNumberInPackingSlip() )
                {
                %>
                <td align="center" nowrap width="15%">

                    <%  if( finalInventoryData.getLotId() == -1 )
                        {
                    %>
                        <input type="text" name="fabLotNumber" size="13" maxLength="50" class="valuetxfield" value='<%=finalInventoryData.getFabLotNumber()%>'>
                    <%
                        }
                        else
                        {
                    %>
                        <font class="NArialL">
                        <%=finalInventoryData.getFabLotNumber()%>
                        </font>
                        <input type="hidden" name="fabLotNumber" value='<%= java.net.URLEncoder.encode( finalInventoryData.getFabLotNumber() , "UTF-8" ).replaceAll( "%27", "\\\\'" ).replaceAll( "\"", "\\\\\"") %>'>
                    <%
                        }
                    %>
                </td>
                <%
                    }
                    else
                    {
                %>

                    <input type="hidden" name="fabLotNumber" value='<%= java.net.URLEncoder.encode( finalInventoryData.getFabLotNumber() , "UTF-8" ).replaceAll( "%27", "\\\\'" ).replaceAll( "\"", "\\\\\"") %>'>
                <%
                    }
                %>
        <td align="center" nowrap width="20%">
            <input type="hidden" name="mktPartNumber" value='<%=finalInventoryData.getMktPartNumber()%>'>
            <input type="hidden" name="locationId" value='<%=finalInventoryData.getLocationId()%>'>
            <input type="hidden" name="balance" value='0'>
            <%  if( finalInventoryData.getLotId() == -1 ) { %>
				<input type="text" name="lotNumber" size="13" maxLength="50" class="valuetxfield" value='<%=finalInventoryData.getLotNumber()%>'>
			<% } else { %>
				<a href="javascript:openAudit('<%= java.net.URLEncoder.encode(  finalInventoryData.getLotNumber() , "UTF-8" ).replaceAll( "%27", "\\\\'" ).replaceAll( "\"", "\\\\\"") %>','<%=finalInventoryData.getLotId()%>')" title='Click here for <%= java.net.URLEncoder.encode(  finalInventoryData.getLotNumber() , "UTF-8" ).replaceAll( "%27", "\\\\'" ).replaceAll( "\"", "\\\\\"") %> Lot Audit Information'  onmouseover="window.status='Click here to Lot Audit Information';return true" onmouseout ="window.status='';return true" ><font class="NArialL">
			        <%=finalInventoryData.getLotNumber()%>
				</font></a>
				<input type="hidden" name="lotNumber" value='<%= java.net.URLEncoder.encode(  finalInventoryData.getLotNumber() , "UTF-8" ).replaceAll( "%27", "\\\\'" ).replaceAll( "\"", "\\\\\"") %>'>
			<% } %>
            <input type="hidden" name="lotId" value='<%=finalInventoryData.getLotId()%>'>
        </td>
         <%
            String dateCode = "enableDateCodeField('" + i + "')";
                    String dateCodevalue = finalInventoryData.getDateCode();

                    //WorkWeek wk = WorkWeek.getCurrentWorkWeekInstance();
                    //String currentDateCode = (wk.getWorkWeekYear() + "").substring(2) + wk.getCurrentWWNumber()+"";
                 //String currentDateCode1 = (wk.getWorkWeekYear() + "").substring(2) + (wk.getCurrentWWNumber()-1)+"";
                 //String currentDateCode2 = (wk.getWorkWeekYear() + "").substring(2) + (wk.getCurrentWWNumber()-2)+"";
        %>
        <td align="center" nowrap width="10%">
			<font class="NArialL">
			<%  if( finalInventoryData.getLotId() == -1 ) { %>
				<input type="text" name="dateCode" maxLength="10" size="10" class="valuetxfield" value='<%=finalInventoryData.getDateCode()%>'>
			<% } else { %>
				<input type="text" class="valuetxfield" name="dateCode" value='<%=finalInventoryData.getDateCode()%>'>
                    <input type="text" style="display:none;" name="dateCode1" class="txfield" size="12" maxlength="20"/>
			<% } %>
			</font>
		</td>
		<td align="left" nowrap width="20%">
			<font class="NArialL">
			<%  if( finalInventoryData.getLotId() == -1 )
				{
					if( finalInventoryData.getDateIn() == null || ( ( StringUtils.formatDateToString (finalInventoryData.getDateIn())).equalsIgnoreCase("null") ) )
					{
			%>
					<input type="text" name="dateIn" maxLength="10" size="12" class="valuetxfield" value=''>
                    <a href="javascript:if(document.finalInventoryForm.dateIn.length!=null){openCalendar(document.finalInventoryForm.dateIn[ '<%=i%>' ])}else{openCalendar(document.finalInventoryForm.dateIn)}"><img onMouseOver="window.status='Click here to select date';return true" border="0" align='center' src="<%=chipTracContext%>/jsp/includes/images/date_selector.gif" height=20 width=20></a>
			<% } else { %>
					<input type="text" name="dateIn" maxLength="10" size="12" class="valuetxfield" value='<%=StringUtils.formatDateToString (finalInventoryData.getDateIn())%>'>
                    <a href="javascript:if(document.finalInventoryForm.dateIn.length!=null){openCalendar(document.finalInventoryForm.dateIn[ '<%=i%>' ])}else{openCalendar(document.finalInventoryForm.dateIn)}"><img onMouseOver="window.status='Click here to select date';return true" border="0" align='center' src="<%=chipTracContext%>/jsp/includes/images/date_selector.gif" height=20 width=20></a>
			<%		}
				} else {
					if( finalInventoryData.getDateIn() != null )
                    {
			%><%=StringUtils.formatDateToString (finalInventoryData.getDateIn())%>
			<%		}%>
				<input type="hidden" name="dateIn" value='<%=finalInventoryData.getDateIn()%>'>
			<% } %>
			</font>
		</td>

		<td align="right" nowrap  width="10%">
			<font class="NArialL">
			<%  if( finalInventoryData.getLotId() == -1 ) { %>
				<input type="text" name="hdnQuantityIn" maxLength="10" size="10" class="valuetxfield" value='<%=finalInventoryData.getQuantityIn()%>' onkeypress="javascript:numericFieldKeyPress( this )" onblur="addQuantity(<%=i%>)">
			<% } else { %>
				<%=StringUtils.formatUnits (finalInventoryData.getQuantityIn())%>
				<input type="hidden" name="hdnQuantityIn" value='<%=finalInventoryData.getQuantityIn()%>'>
			<% } %>
			</font>
            <% if (!viewOnly) { %>
			<input type=hidden name=initBalances value='<%=finalInventoryData.getBalance()%>' >
            <input type="hidden" name="balance" >
		<% } %>
		</td>

		<td align="center" nowrap  width="10%"><font class="NArialL">
        <%
                    String qtyToPull = "";
                    if ( finalInventoryData.getQuantityPull() > 0 )
                    {
                        qtyToPull = finalInventoryData.getQuantityPull()+"";
                        totalQtyPull += finalInventoryData.getQuantityPull();
                    }
            		if (viewOnly)
                    {
                        out.print ( ( StringUtils.formatUnits( qtyToPull ) == null ) ? "" : StringUtils.formatUnits( qtyToPull ) );
                    }
                    else
                    {
		%>
			<input type="text" size="8" name="quantityToPull" onkeyup='addQuantity(<%=i%>)'  onkeypress="javascript:numericFieldKeyPress( this )" value='<%=qtyToPull%>' class='valuetxfield'></font>
            <% if( finalInventoryData.getLotEnteredBy()==null ) { %>
                <input type="hidden" name="lotEnteredBy" value='0'>
            <% } else { %>
                <input type="hidden" name="lotEnteredBy" value='<%=finalInventoryData.getLotEnteredBy() %>'>
            <% } %>
            <input type="hidden" name="lotBalanceQty" value='<%=finalInventoryData.getHiddenBalance() %>'>
			<input type="hidden" name="quantityToPullHidden" value='<%=qtyToPull%>'>
			<input type="hidden" name="csLineItemId" value='<%=finalInventoryData.getCsLineItemId()%>'/>
        <%
					}
		%>
        </td>
        <% if ( ( viewOnly == true ) || ( reqFromVendorInterface != null ) ) { %>
            <%  if ( reqFromVendorInterface == null ) { %>
                <td align="center" nowrap  width="15%"><font class="NArialL">
            <%
                   if (  finalInventoryData.getLotEnteredBy() !=  null &&  finalInventoryData.getLotEnteredBy().equalsIgnoreCase("0") ) {
                    out.print ("(DataEntry)");
                   } else {
                    out.print ("(Adaptor)");
                   }
            %></td><%
            }
            %>
            </td>
        <% } else { %>
            <td align="center" nowrap  width="10%"><font class="NArialL">
                <% if (  finalInventoryData.getLotEnteredBy() !=  null &&  finalInventoryData.getLotEnteredBy().equalsIgnoreCase("0") && finalInventoryData.getIsReduceBalance() == -1 ) { %>
                    <input type="checkbox" name="isReduceBal" checked="checked">(DataEntry)
                <% } else if ( finalInventoryData.getLotEnteredBy() !=  null &&  finalInventoryData.getLotEnteredBy().equalsIgnoreCase("0") && finalInventoryData.getIsReduceBalance() == 0 ) { %>
                    <input type="checkbox" name="isReduceBal" checked="checked">(DataEntry)
                <% } else if ( finalInventoryData.getLotEnteredBy() !=  null &&  finalInventoryData.getLotEnteredBy().equalsIgnoreCase("1") && finalInventoryData.getIsReduceBalance() == 0 ) { %>
                    <input type="checkbox" name="isReduceBal" checked="checked">(Adaptor)&nbsp;&nbsp;&nbsp;
                <% } else if ( finalInventoryData.getLotEnteredBy() !=  null &&  finalInventoryData.getLotEnteredBy().equalsIgnoreCase("0") && finalInventoryData.getIsReduceBalance() == 1 ) { %>
                    <input type="checkbox" name="isReduceBal">(DataEntry)
                <% } else if ( finalInventoryData.getLotId() == -1 && finalInventoryData.getIsReduceBalance() == 0 ) { %>
                    <input type="checkbox" name="isReduceBal" checked="checked">(DataEntry)
                <% } else if ( finalInventoryData.getLotId() == -1 && finalInventoryData.getIsReduceBalance() == 1 ) { %>
                    <input type="checkbox" name="isReduceBal">(DataEntry)
                <% } else { %>
                    <input type="checkbox" name="isReduceBal">(Adaptor)&nbsp;&nbsp;&nbsp;
                <% } %>
            </td>
        <%
        }
        %>
	</tr>
        <% } // for loop ends here %>
	<input type="hidden" name="noOfLots" value='<%=size++%>'/>
    <tr id="rowIndex"><td width="100%" colspan='12'>&nbsp;<font id='font1'></font></td></tr>
    <% if( !request.getParameter( "viewonly" ).equalsIgnoreCase( "true" ) ) { %>
	<tr>
        <td  colspan="7" align="right">
        <% if( parentPartNoExitsInSubs == true ) { %>
        <font class='NArialL'><a href="javascript:addMore('<%=request.getParameter ("parentPartNo")%>', '<%=request.getParameter ("shippingFromAddressId")%>', '<%=finalInventoryData.getCsLineItemId()%>');" onmouseover="window.status='Click here to add new lot';return true" onmouseout ="window.status='';return true" >Click here to add new Lot</a></font>
        <% } %>
        </td>
	</tr>
	<% } %>
	<tr><td colspan='7'><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20></td></tr>
	<tr>
        <td width="100%" colspan='7'>
            <table width="100%" border="0">
                <tr>
                    <td align='right'><font class='NArialL'>Total Quantity to be Shipped:</font></td>
                    <td><input type="text" size='4' name="qtyTobeShipped" class='NArialL' style="BORDER-BOTTOM: thin; BORDER-LEFT-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-TOP: thin; CLEAR: none; COLOR: red;font-family: arial;font-size: 10pt;font-weight:bold " value='<%=quantityToBeShipped%>' readOnly disabled>
                    <%--<script>calcQtyToBeShipped();</script>--%>
                    <script>calcDynValues();</script>
                    </td>
                    <td align='right'><font class='NArialL'>Total Quantity Pulled:&nbsp;&nbsp;</font></td>
                    <td><input type="text" size='4' name="totals" class='NArialL' style="BORDER-BOTTOM: thin; BORDER-LEFT-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-TOP: thin; CLEAR: none; COLOR: red;font-family: arial;font-size: 10pt;font-weight:bold " value="" readOnly disabled><script>document.finalInventoryForm.totals.value='<%=totalQtyPull%>'</script></td>
                </tr>
           </table>
       </td>
	</tr>
	<tr><td colspan='7'><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=30></td></tr>
    <% } %>
	<tr>
		<td colspan='7' align=center>
		<% if ( ( viewOnly ) || ( finalInventoryDataList == null ) || ( ( finalInventoryDataList.isEmpty() == true ) &&  request.getParameter( "dropShip" ).equalsIgnoreCase( "false" ) ) ) { %>
			<a href="javascript:window.close()"  onmouseover="window.status='Click here to close';return true" onmouseout ="window.status='';return true"  ><font class='NArialL'>[Close this window]</font></a>
		<% } else { %>
			<%--<chiptrack:restrictedLink functionality='<%=Functionality.PACKING_SLIP%>' action='<%=User.USER_ACTION_MODIFY%>' href='javascript:window.saveData()' onmouseover="window.status='Click here to save';return true" onmouseout ="window.status='';return true"> <img border="0" src="<%=chipTracContext%>/jsp/includes/images/save.gif" width="53" height="17"></chiptrack:restrictedLink>--%>
            <a href='javascript:window.saveData()' onmouseover="window.status='Click here to save';return true" onmouseout ="window.status='';return true"> <img border="0" src="<%=chipTracContext%>/jsp/includes/images/save.gif" width="53" height="17"></a>
			&nbsp;&nbsp;&nbsp;
			<a href="javascript:resetValues()" onmouseover="window.status='Click here to reset values';return true" onmouseout ="window.status='';return true" title='Click here to reset all field values'><img border="0" src="<%=chipTracContext%>/jsp/includes/images/reset.gif" width="53" height="17"></a>&nbsp;&nbsp;&nbsp;
			<a href="javascript:window.close()" onmouseover="window.status='Click here to close';return true" onmouseout ="window.status='';return true"  title='Click here to close the window'><img border="0" src="<%=chipTracContext%>/jsp/includes/images/cancel.gif" width="53" height="17"></a>
		<% } %>
		</td>
	</tr>
	<tr><td colspan='7'><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=30></td></tr>
</html:form>
</table>

<% } else { %>
    <table cellpadding='0' cellspacing='0' bgcolor='FDF5E6' border="0" width="100%"  height="100%" align=center>
        <tr>
            <td>
                <table align="center" border="0" width="40%" bgcolor="#FDF5E6">
                    <tr><td>&nbsp;</td></tr>
                    <tr><td align="center" ><font class="NArialL" ><font color="red">Session has been time out , Please close this window and login again.</font></font></td></tr>
                    <tr><td>&nbsp;</td></tr>
                    <tr><td align="center" ><a href="javascript:window.close();"  onmouseover="window.status='Click here to close';return true" onmouseout ="window.status='';return true"  title='Click here to close the window'><font class='NArialL'>[Close this window]</font></a></td></tr>
                </table>
            </td>
       </tr>
       <tr><td>&nbsp;</td></tr>
    </table>
<% } %>

</body>
</html:html>
